package com.huaxindata.im.model.contact;

import android.os.Parcel;
import android.os.Parcelable;

import com.huaxindata.im.model.entity.ChatMessage;

/**
 * 群对象,注意ContactGroup继承了Contact的三个属性
 * 在构造方法中初始化ContactGroup对象的时候要将这三个属性初始化
 * 不然用的时候会报空指针异常
 */
public class ContactGroup extends Contact implements Parcelable{
    /**
     * {
     "groupMain": 449,
     "groupMembers": "449,50,378",
     "groupMembersImg": "http://www.iwatercloud.cn:8081/uploads/image/userHeadImg/20170721141152060.jpg, ,http://www.iwatercloud.cn:8081/uploads/image/userHeadImg/20170629104300896.jpg",
     "groupName": "gkl测试群",
     "groupMembersNickName": "郭凯林,管理员,Hong",
     "groupClientId": "g935h6_148",
     "groupIcon": ""
     }
     */
    public String groupMain;//群主
    public String groupMembers;//群成员
    public String groupMembersImg;//群成员的头像
    public String groupName;//群名称
    public String groupMembersNickName;//群成员昵称
    public String groupClientId;//群id
    public String groupIcon;//群头像

    private String[] groupMemberId;
    public String[] peoples;
    public String[] nickNames;
    public String[] icons;

    @Override
    public String getClientId() {
        return groupClientId;
    }

    @Override
    public String getIcon() {
        return groupIcon;
    }

    @Override
    public String getNickName() {
        return groupName;
    }

    public ContactGroup(String groupClientId, String groupMain, String groupName, String groupIcon){
        this.groupClientId=groupClientId;
        this.groupMain=groupMain;
        this.groupName=groupName;
        this.groupIcon=groupIcon;
        //初始化父类对象
        this.clientId=groupClientId;
        this.icon=groupIcon;
        this.nickName=groupName;
    }

    public String getGroupMain() {
        return groupMain;
    }

    public void setGroupMain(String groupMain) {
        this.groupMain = groupMain;
    }

    public String getGroupMembers() {
        return groupMembers;
    }

    public void setGroupMembers(String groupMembers) {
        this.groupMembers = groupMembers;
        this.groupMemberId = groupMembers.split(",");
        this.peoples = groupMembers.split(",");
    }
    public String[] getGroupMemberId(){
        return this.groupMembers.split(",");
    }
    public String getGroupMembersImg() {
        return groupMembersImg;
    }

    public void setGroupMembersImg(String groupMembersImg) {
        this.groupMembersImg = groupMembersImg;
        icons = groupMembersImg.split(",");
    }

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public String getGroupMembersNickName() {
        return groupMembersNickName;
    }

    public void setGroupMembersNickName(String groupMembersNickName) {
        this.groupMembersNickName = groupMembersNickName;
        nickNames = groupMembersNickName.split(",");
    }

    public String getGroupClientId() {
        return groupClientId;
    }

    public void setGroupClientId(String groupClientId) {
        this.groupClientId = groupClientId;
    }

    public String getGroupIcon() {
        return groupIcon;
    }

    public void setGroupIcon(String groupIcon) {
        this.groupIcon = groupIcon;
    }

    public String getDuty() {
        if (duty != null) {
            return duty;
        }
        return duty = "共" + getGroupMemberId().length + "人";
    }
    protected ContactGroup(Parcel in) {
        groupClientId=in.readString();
        groupIcon=in.readString();
        groupName=in.readString();
        groupMain=in.readString();
        groupMembers=in.readString();
        groupMembersImg=in.readString();
        groupMembersNickName=in.readString();
    }

    public static final Parcelable.Creator<ContactGroup> CREATOR = new Parcelable.Creator<ContactGroup>() {
        @Override
        public ContactGroup createFromParcel(Parcel in) {
            return new ContactGroup(in);
        }

        @Override
        public ContactGroup[] newArray(int size) {
            return new ContactGroup[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(groupClientId);
        dest.writeString(groupIcon);
        dest.writeString(groupName);
        dest.writeString(groupMain);
        dest.writeString(groupMembers);
        dest.writeString(groupMembersImg);
        dest.writeString(groupMembersNickName);
    }
    @Override
    public String toString() {
        return groupClientId + ChatMessage.PREX
                + groupName + ChatMessage.PREX
                + groupMain + ChatMessage.PREX
                + groupMembers + ChatMessage.PREX
                + (groupIcon == null ? "" : groupIcon);
    }
}
